home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-10 | 12.3 KB | 255 lines | [TEXT/sade] |
- ##########################################################################################
- # Symbolic Application Debugging Environment 1.4
- #
- # copyright Apple Computer, Inc. 1987-1992
- # All rights reserved.
- #
- ##########################################################################################
- # You may be able to use Sade using only Menu commands. However, if you are
- # doing some things repeatedly, you may save time by learning to write some
- # commands, saving them, using them the next time around.
- # This worksheet contains some commands you might like to try.
- # It also contains a section on how to debug MPW tools, and MacApp code.
- #
- ###############################################################################
- # Execute commands in the Worksheet as in MPW with the Enter key. With a command
- selected, you can also click on the status box in the upper left hand corner;
- which has identical effect.
-
- Version # To display SADE's version information; or use About SADE in Apple menu.
-
- Help # Get a list of help topics; or use SADE Help menu command in Find menu.
-
- # When you compile and link your application, specify the -sym on option to create
- # the file containing symbol information (.SYM) that SADE requires for debugging.
-
- # Note that the following commands use one of the sample applications that comes
- # with the SADE disk. Substitute a different sample application or one of your own
- # applications if you wish.
-
- # Identify the target application to debug and its symbol file:
- Directory 'SADE:SADE Tutorials:CExamples:C Tutorial 1'
- # Sourcepath 'pathname1','pathname2' # This command is not necessary with Sample1
- # because its source is in one directory. Use
- # SourcePath only if your source files are in
- # multiple directories or in a different
- # directory than your application.
- Target 'Sample1' # assumes symbol file is 'Sample1.SYM'
-
- # You will see that Target not only identifies the application but launches it, opens
- # the source file, and breaks at the first statement of the main program.
-
- # Now select a statement of interest; e.g., DoMenuCommand (use the Mark menu), and
- # choose the Go Til command from the SourceCmds menu. SADE sets a temporary
- # breakpoint on DoMenuCommand and resumes operation of Sample1 (the traffic light
- # appears). SADE will be reentered when the breakpoint is encountered; in this case,
- # choose Red Light from the Traffic menu and SADE highlights DoMenuCommand in the
- # source file.
-
- # Now choose a variable to watch, e.g., gStopped, which tells whether the light is
- # Red (TRUE) or green (FALSE); highlight gStopped here and select Add Watch Variable
- # from the Variables menu. SADE opens a window displays its current value. SADE will
- # also show its new value whenever you step.
-
- # Now step the program using Step in the SourceCmds menu. If you want to step into a
- # routine use the Step Into menu command. For example, after 4 or 5 steps you can
- # step into the SetLight routine when SetLight (FrontWindow(), false); is highlighted.
- # Within the SetLight routine, gStopped should change to 0.
-
- # To remove Sample1 as the target, issue this command:
- Kill
-
- ###############################################################################
- # When your application is running, you can suspend it and enter SADE by
- # pressing <command-option> <SADEKey>.
- # The default SADEKey is <numeric-key-pad-period>.
- # To change it, modify and execute the following:
-
- SADEKey <new key code>
-
- # See Inside Macintosh Volume 5, pages 191-192 for the key codes for the various keyboards.
-
- ###############################################################################
- # Debugging Object Pascal and MacApp
- MacApp methods are supported. Within methods, references to the instance
- variables of the object can be made without qualifying those references by SELF.
- These free references to instance variables can also be done in C++ member
- functions.
-
- A SADE variable, BreakIfNoSource, defaults to 0. When 0, a Step Into will
- continue stepping until there is source statement information available for the
- instruction at the program counter. Stepping into a method call will break
- at the first instruction of the method. The down side is that if SADE steps into
- something without statement information, it will appear SADE has hung. It hasn't,
- it's just very busy executing your code 2 to 3 orders of magnitude slower than
- normal. This down side should only affect you if you step into code which has
- been built without symbols. Should you do so, you have a choice of waiting for
- completion of stepping or rebooting. Setting BreakIfNoSource to 1 will make
- SADE break when no source information is available for the PC.
-
- To step into a method use the Step Into menu item from the SourceCmds menu
- (Source vs Asm checked in SourceCmds) or the Step Line Into command and options.
- To avoid stepping through MacApp's method dispatch code, you should assemble
- MacApp's ≈.a files with "-SYM OFF". Also, UObject.p.o and UMacAppUtilities.p.o
- should be compiled with "-SYM OFF" because routines in these files are called as
- part of the method dispatch.
-
- Follow these simple steps when debugging MacApp code with SADE. Assume the
- target is the MacApp sample program DemoDialogs:
-
- (1) In MPW, set the directory to the location of your sourcefiles and build your
- application with symbol information:
- directory "hd:MacApp® 2.0.1:Examples:DemoDialogs:"
- mabuild -sym -autobuild DemoDialogs
- The -autobuild option will build the MacApp libraries if necessary.
-
- (2) Double click on the DemoDialogs.sym file from the Finder. The file should
- be located in the newly created .NoDebug Sym folder within the sources folder.
- This will launch SADE, set the directory and sourcepath and target DemoDialogs.
- However, SADE still does not know where the MacApp libraries are located and so
- you will be prompted to locate them if you attempt to step into a MacApp method
- or suspend execution in a MacApp method.
-
- You may wish to launch SADE and setup the directory and sourcepath variables
- yourself before targeting DemoDialogs. To do so, execute the following commands
- from SADE:
- directory "hd:MacApp® 2.0.1:Examples:DemoDialogs:.NoDebug Sym:"
- Sourcepath "hd:MacApp® 2.0.1:Examples:DemoDialogs:", ∂
- "hd:MacApp® 2.0.1:Libraries:"
- Target 'DemoDialogs'
-
- The file MDemoDialogs.cp should now be open and the program counter should be at
- the first statement: void main ()
-
-
- ###############################################################################
- # Low-level Debugging
- # You can set SourceCmds menu to Asm Debugging.
- # If you use Step menu command now, SADE executes one instruction at a time rather
- # than one source statement at a time.
-
- # Here are some commands you can use for low-level debugging:
- Stack # Show the address of, owner, and caller of all
- # stack frames- see also the section below on
- # 'SADE Example Scripts' for a useful script to
- # do stack crawls based on A7 rather than A6
-
- Disasm pc 10 # Disassemble 10 instructions starting from the pc
-
- Disasm myProc.(1) # Disassemble 20 (the default) instructions starting
- # from the first statement of procedure myProc
-
- Dump a0 64 # Display 64 bytes beginning at location pointed to
- # by register a0
-
-
- # Macintosh System Structures
-
- heap # Display the heap pointed at by theZone
- heap check # Validate the heap pointed at by theZone
- resource # displays all open resource maps in target application
-
- windowList^ # Display FrontWindow as a grafPort
- ^WindowRecord(windowList)^ # Display FrontWindow as a windowRecord
- *(WindowRecord *)(windowList) # doing the same with a C expression
-
- ###############################################################################
- # Source Level Debugging (Set SourceCmds to Source Debugging)
- # If you use Step menu command, SADE steps one source statement at a time. Here is
- # a procedure for stepping a given number of times; note the use of the onEntry
- # keyword, which tells SADE what to do after each step; in this case, take another
- # step.
- define StepCount
- proc __Step__
- if (StepCount > 0)
- StepCount := StepCount - 1;
- step onentry __step__
- end
- end
- proc StepN(__n__)
- StepCount := __n__
- Step OnEntry __Step__
- end
-
- StepN (3) # Step three times
-
- # After you're finished, you may wish to undefine StepCount.
- undefine StepCount
-
-
- ###############################################################################
- # To debug an MPW tool (using the example tool Count), compile and link the tool
- # with symbolic information (-sym on|full). Be sure to specify the file type and
- # creator when you Link an MPW tool:
- Link -t 'MPST' -c 'MPS ' -sym on
-
- # From the Finder, double-click on the tool's SYM file. This will launch SADE, set the
- # directory and target the tool. As long as MPW is still running, SADE will make MPW
- # the frontmost application. Otherwise, SADE will prompt you to locate the MPW Shell
- # and then it will launch MPW. You may then run your tool from MPW and SADE will
- # execute it, stopping at the first line of the main program.
-
- # Another way of targeting a tool would be to execute the following commands from
- # SADE to set the directory and target the tool. After MPW is launched, run the tool.
-
- Directory "hd:mpw:Examples:CExamples:"
- Target "hd:mpw:mpw shell" using "Count.SYM"
-
- # To remove the tool as the target, kill the tool using either the Kill menu
- # command (which calls KillTool) or issue KillTool from the SADE worksheet.
- # Do not issue the Kill command from the worksheet. This will kill MPW.
- # KillTool will shutdown the tool and leave MPW running, so you can continue to
- # work in MPW if you wish.
- KillTool
-
-
- ###############################################################################
- # The folder 'SADE Example Scripts' contains files with examples of the SADE language.
- # You might find these interesting if you are attempting to write your own scripts.
- # To execute these scripts, you must first target an application. Then set the
- # directory to the folder containing the scripts.
-
- Directory concat (SADEDir,'SADE Example Scripts:') # SADEDir is defined in SADEStartup
-
- # Then select any line beginning with 'execute' and press Enter; commands nested
- # under the execute line represent procedures defined in the script files and
- # can then be run as well.
-
- Execute 'MiscProcs'
- DisplayFCBs # Displays information about all open files
- displaywindowlist # Displays the name of each open window in the target application.
- InterList('routine name', 'output filename') # interleaves statements and associated instructions
- factorial (20) # Evaluate the factorial of 20 and printout the results
-
- Execute 'Resource'
- ResMap "CODE" # Display information about all CODE resources.
- ResMap # SLOWLY mimics the resource command
- ResVerify # mimics the resource check command
-
- Execute 'sc7'
- StackCrawl7 # Display a possible calling chain sequence. There is
- # also a macro 'sc7' defined in the script which executes
- # stackcrawl7.
-
-
- ###############################################################################
- # Command Key Equivalents: The AddMenu command allows you to add new menus to the
- # SADE menu bar. You can optionally add a key equivalent for any of the menus you
- # create by preceding the key with a frontslash. Since the SourceCmds and Variables
- # menus are both defined in the file SADEStartup, you can change the key equivalents
- # for the commands defined in those menus if you wish.
-
- # For instance, the key equivalent for Show Dereferenced Value is Command-◊, or
- # Command-Option-Shift-V. If you find this a difficult key combination to press, you
- # may change it by replacing '◊' with a different character. The best place to make
- # this change is in a SADEUserStartup•≈ file that you create. Since any such file will
- # be executed after SADEStartup when SADE is launched, your changes will overwrite the
- # same command defined in SADEStartup, but will leave SADEStartup untouched.
-
- # Show Dereferenced Value as defined in SADEStartup:
- addmenu 'Variables' 'Show Dereferenced Value /◊' 'ShowDereferencedValue(selection(ActiveWindow))'
-
- # Create a file SADEUserStartup•MyName and add this line to change the key equivalent only.
- # This example changes the key equivalent to Command-9.
- addmenu 'Variables' 'Show Dereferenced Value /9' 'ShowDereferencedValue(selection(ActiveWindow))'
-